<?php	

	include("connect.php");
	
	$id = $_POST["id"];
	
	// Get full imagename from database
	$result = mysql_query("SELECT filename FROM images WHERE id='".$id."'");
	$array = mysql_fetch_array($result);
	$imageName = $array[0];
	
	// Delete image from server
	unlink("../img/gallery/".$imageName);

	// Delete image info from database
	mysql_query("DELETE FROM images WHERE id='".$id."'");
	
	// Renumber images
	$result2 = mysql_query("SELECT * FROM images ORDER BY listorder") or die(mysql_error());
	$count = 0;
		
	while($row = mysql_fetch_array($result2))
	{		
		mysql_query("UPDATE images SET listorder='".$count."' WHERE id='".$row[id]."'");
		$count++;
	}
	
?>